import axios from 'axios'
import store from '@/lib/store/store'

const srv= axios.create({
    baseURL: '', //基础API地址
    timeout: 15000 //超时时间
})
srv.interceptors.response.use(
    function(response){
        //正常返回
        return Promise.resolve(response)
    },
    function(error){
        //请求错误向store提交这个状态变化
        const httpError= {
            hasError: true,
            status: error.response.status,
            statusText: error.response.statusText
        }
        store.commit('ON_HTTP_ERROR', httpError)
        return Promise.reject(error)
    }
)
export default srv